package adapter;

public class Customer {
	public static final String US = "US";
	public static final String CANADA = "Canada";
	private String address;
	private String name;
	private String zip, state, type;

	/**
	 * @param address
	 * @param name
	 * @param zip
	 * @param state
	 * @param type
	 */
	public Customer(String address, String name, String zip, String state,
			String type) {
		super();
		this.address = address;
		this.name = name;
		this.zip = zip;
		this.state = state;
		this.type = type;
	}

	public boolean isValidAddress() {
		AddressValidator validator = getValidator(type);

		if (validator == null) {
			throw new NullPointerException("Cannot get an address validator!");
		}

		return validator.isValidAddress(address, zip, state);
	}

	private AddressValidator getValidator(String custType) {
		AddressValidator validator = null;

		if (custType.equals(Customer.US)) {
			validator = new USAddress();
		}

		if (custType.equals(Customer.CANADA)) {
//			validator = new roy.study.adapter.clazz.CAAddressAdapter();
			validator = new adapter.object.CAAddressAdapter();
		}

		return validator;
	}
}
